unit SerjUtils;

interface

uses
  Windows;

  function WordToStr(const S: word): string;
  function StrToWord(const S: string): word;


implementation

function WordToStr(const S: word): string;
  {$IFDEF USE_INLINE} inline; {$ENDIF}
begin
  {$IFDEF STRING_IS_UNICODE}
  Result := BytesToStringRaw(ToBytes(Value));
  {$ELSE}
  SetLength(Result, SizeOf(S));
  Move(S, Result[1], SizeOf(S));
  {$ENDIF}
end;

function StrToWord(const S: String): Word;
{$IFDEF USE_INLINE} inline; {$ENDIF}
begin
  if Length(S) > 1 then begin
    {$IFDEF STRING_IS_UNICODE}
    Result := TwoCharToWord(Value[1], Value[2]);
    {$ELSE}
    Result := PWord(Pointer(S))^;
    {$ENDIF}
  end else begin
    Result := 0;
  end;
end;



end.
